package com.itheima.mapper;

import com.itheima.pojo.Student;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * The interface Student mapper.
 */
@Mapper
public interface StudentMapper {

    /**
     * 分页查询学员列表
     *
     * @param name          the name
     * @param highestDegree the highest degree
     * @param classesId     the classes id
     * @param studentNumber the student number
     * @return the list
     */
    List<Student> selectStudentByPage(String name, Integer highestDegree, Integer classesId, String studentNumber);

    /**
     * 新增学员
     *
     * @param student the student
     */
    void addStudent(Student student);

    /**
     * 根据id删除学员
     *
     * @param id the id
     */
    @Delete("delete from student where id = #{id}")
    void deleteStudentById(Integer id);

    /**
     * 根据id查询信息
     *
     * @param id the id
     * @return the student
     */
    @Select("select * from student where id = #{id}")
    Student selectStudentById(Integer id);

    /**
     * 根据id更新学员信息
     *
     * @param student the student
     */
    void updateStudentById(Student student);

    /**
     * 违纪扣分
     *
     * @param student the student
     */
    void updateStudentForDeductions(Student student);

    /**
     * 通过学号查询学号是否重复
     *
     * @param studentNumber the student number
     * @return the integer
     */
    @Select("select count(*) from student where student_number = #{studentNumber}")
    Integer selectCountByStudentNumber(String studentNumber);

    /**
     * 通过学号查询学号是否重复并且排除自身的干扰
     *
     * @param studentNumber the student number
     * @param id            the id
     * @return the integer
     */
    @Select("select count(*) from student where student_number = #{studentNumber} and id != #{id}")
    Integer selectCountByStudentNumberNotId(String studentNumber, Integer id);

    /**
     * 通过手机号查询手机号是否重复
     *
     * @param phone the phone
     * @return the integer
     */
    @Select("select count(*) from student where phone = #{phone}")
    Integer selectCountByPhone(String phone);

    /**
     * 通过手机号查询手机号是否重复并且排除自身的干扰
     *
     * @param phone the phone
     * @param id    the id
     * @return the integer
     */
    @Select("select count(*) from student where phone = #{phone} and id != #{id}")
    Integer selectCountByPhoneNotId(String phone, Integer id);
}
